1
00:00:00,090 --> 00:00:06,870
Now we're moving on to conditional statements now you could give conditional statements as an if else

2
00:00:06,930 --> 00:00:08,020
scenario.

3
00:00:08,220 --> 00:00:14,670
For example if you go to the store and you want to purchase a drink and the drink cost two dollars.

4
00:00:15,360 --> 00:00:19,840
Well if you have two dollars you're going to be able to purchase that drink.

5
00:00:20,100 --> 00:00:24,570
If you don't have two dollars then you won't be able to purchase that drink.

6
00:00:24,630 --> 00:00:26,040
That is a condition.

7
00:00:26,040 --> 00:00:30,390
So the condition there is based on the amount of money you have.

8
00:00:30,390 --> 00:00:39,180
We can take these conditional statements and we can run if else we could also run if else if else and

9
00:00:39,180 --> 00:00:40,460
build upon these.

10
00:00:40,470 --> 00:00:44,630
Now it all makes sense when we start putting it together in our script here.

11
00:00:44,640 --> 00:00:53,190
So let's go ahead and just do that let's make a new line and let's make a comment here that says conditional

12
00:00:53,190 --> 00:00:56,580
statements.

13
00:00:57,300 --> 00:00:59,100
And let's start with a conditional statement.

14
00:00:59,100 --> 00:01:02,960
So a conditional statement is going to start off looking like a function.

15
00:01:03,000 --> 00:01:09,990
So we'll say define and here let's make the same scenario where we talked about the money and buying

16
00:01:09,990 --> 00:01:10,980
into ring.

17
00:01:11,070 --> 00:01:18,960
So we'll define drink and we'll just say a parameter here of money.

18
00:01:19,350 --> 00:01:19,700
OK.

19
00:01:19,710 --> 00:01:27,090
And then let's invent and let's say if money is greater than or equal to to me where we talked about

20
00:01:27,090 --> 00:01:33,980
two dollars for this drink then we're going to return.

21
00:01:35,200 --> 00:01:39,500
You've got yourself a drink.

22
00:01:40,050 --> 00:01:43,330
Now what if we don't have the money.

23
00:01:43,530 --> 00:01:50,460
So we could say else if our money is not greater than or equal to two then we're just going to return

24
00:01:54,180 --> 00:02:03,330
no drink for you didn't mean to capitalize the o there but I'm leaving it because I like it.

25
00:02:04,170 --> 00:02:08,580
So in this situation we have our conditions set.

26
00:02:09,000 --> 00:02:15,860
Now again if our money equals or EAP is equal to or greater than two we're gonna get a drink.

27
00:02:16,110 --> 00:02:18,260
And if not we're not going to get a drink.

28
00:02:18,510 --> 00:02:19,620
So it could be anything else.

29
00:02:19,620 --> 00:02:19,950
Right.

30
00:02:20,850 --> 00:02:28,590
So what we can do now is since this is just returning and not printing anything we can print out something

31
00:02:28,590 --> 00:02:32,550
like a drink and then we specify the amount.

32
00:02:32,550 --> 00:02:35,820
So if we have three we should return one thing.

33
00:02:35,940 --> 00:02:41,200
And if we print drink here with only a dollar we should return another.

34
00:02:41,350 --> 00:02:47,540
Let's go ahead and save this script and I didn't put this with an ampersand so I'm going to close out

35
00:02:47,540 --> 00:02:49,180
and make sure I do that next time.

36
00:02:49,490 --> 00:02:57,580
And we're gonna do is we're just going to go ahead and Python 3 script up high and you can see down

37
00:02:57,580 --> 00:03:03,870
here we go back and let me run this script with the ampersand.

38
00:03:04,010 --> 00:03:08,680
You can see that we did a drink of three which we were expecting to return.

39
00:03:08,680 --> 00:03:09,800
You've got yourself a drink.

40
00:03:10,310 --> 00:03:16,380
And we did a drink of one which we're expecting to return no drink for you this happened just the way

41
00:03:16,380 --> 00:03:17,220
we thought it would.

42
00:03:18,060 --> 00:03:21,240
So we can build upon these conditional statements.

43
00:03:21,270 --> 00:03:24,800
Let's talk about a different scenario with multiple parameters.

44
00:03:24,870 --> 00:03:31,350
Let's say that you are an adult and here in the United States if you're an adult and you want to have

45
00:03:31,350 --> 00:03:36,780
a drink of alcohol that requires you to be of age at twenty one.

46
00:03:36,780 --> 00:03:42,450
So in order to purchase alcohol you have to be one of age and to have money.

47
00:03:42,510 --> 00:03:44,300
Now if you don't drink that's perfectly OK.

48
00:03:44,310 --> 00:03:46,770
This is just a example scenario.

49
00:03:47,340 --> 00:03:51,120
So here let's say we wanted to buy alcohol.

50
00:03:51,120 --> 00:03:55,650
We have to meet that age requirement of 21 and we have to meet the requirement of money.

51
00:03:55,680 --> 00:04:00,720
Now we could be in a situation where we meet the age requirement but we don't meet the money or we could

52
00:04:00,780 --> 00:04:01,910
meet the money requirement.

53
00:04:01,950 --> 00:04:07,470
But we don't meet the age requirement or we could be in a situation where we don't meet the age requirement

54
00:04:07,590 --> 00:04:09,940
and we don't meet the money requirement.

55
00:04:10,020 --> 00:04:15,520
So let's set this up to think through this and how these scenarios could play out.

56
00:04:15,720 --> 00:04:23,940
So let's define alcohol here and we need two parameters we're going to say age and money

57
00:04:26,740 --> 00:04:35,050
so first statement here is gonna be our leading if we're going to say if age is greater than or equal

58
00:04:35,050 --> 00:04:42,720
to 21 because we need that condition to be true and our money is greater than or equal to 5.

59
00:04:42,730 --> 00:04:46,810
So let's say a drink cost five dollars we're going to return

60
00:04:49,770 --> 00:04:51,760
we're getting a drink

61
00:04:54,460 --> 00:05:00,850
OK now since we're gonna have multiple conditions here we're going to introduce something called else

62
00:05:00,940 --> 00:05:01,650
if.

63
00:05:01,870 --> 00:05:04,960
Else if here is written like this.

64
00:05:04,960 --> 00:05:20,200
E L I F so else if our age is greater than or equal to twenty one and R money is less than five dollars

65
00:05:21,340 --> 00:05:22,930
then let's return

66
00:05:25,730 --> 00:05:28,030
come back with more money.

67
00:05:31,170 --> 00:05:35,790
We need another else here because we have another condition right.

68
00:05:35,820 --> 00:05:46,560
So we're gonna say whatever our age is less than twenty one and our money is greater than or equal to

69
00:05:46,560 --> 00:05:47,220
five.

70
00:05:48,300 --> 00:05:52,740
Well we're going to return.

71
00:05:52,920 --> 00:05:57,690
Nice try kid because we're not old enough to purchase this drink.

72
00:05:57,690 --> 00:06:05,940
And then lastly and our else scenario if we are not meeting any of the conditions above which means

73
00:06:05,940 --> 00:06:14,520
we won't have the age we won't have the money then we're just going to return here to like a type sorry

74
00:06:15,020 --> 00:06:24,390
you're too poor and too young so let's go ahead and run this a couple different times.

75
00:06:24,580 --> 00:06:31,670
So let's go ahead and print out alcohol and we're going to give our two parameters let's say twenty

76
00:06:31,670 --> 00:06:41,250
one in five let's print out again alcohol and let's give a parameter of twenty one and four and then

77
00:06:41,250 --> 00:06:49,980
let's print out one last time of alcohol and we'll say that we are 20 and four so we should meet a few

78
00:06:49,980 --> 00:06:51,200
different conditions here.

79
00:06:51,210 --> 00:06:51,930
Right.

80
00:06:52,020 --> 00:06:58,650
So at twenty one in five we should return we're getting a drink at 21 and four we should return come

81
00:06:58,650 --> 00:07:03,300
back with more money and at 20 and 4 we should return.

82
00:07:03,330 --> 00:07:05,380
You're too poor and too young.

83
00:07:05,480 --> 00:07:10,800
Now if you want to add in a fourth condition here or a fourth print statement and you want to return

84
00:07:10,800 --> 00:07:13,530
the Nice try kid you're more than welcome to do that as well.

85
00:07:13,680 --> 00:07:14,240
So go ahead.

86
00:07:14,250 --> 00:07:18,860
Hey control ask or save your script out and then let's go ahead and run it

87
00:07:22,440 --> 00:07:25,830
and you can see it we return exactly where we thought we're going to.

88
00:07:25,830 --> 00:07:27,360
We're getting a drink.

89
00:07:27,360 --> 00:07:32,550
Come back with more money and you too poor and too young.

90
00:07:32,610 --> 00:07:36,000
So this is it for conditional statements.

91
00:07:36,060 --> 00:07:40,850
Hopefully this makes sense again our conditions are based on certain items.

92
00:07:40,860 --> 00:07:41,160
Right.

93
00:07:41,190 --> 00:07:45,030
So money here for an example if we have the money we're getting a drink.

94
00:07:45,030 --> 00:07:49,290
If we don't have the money we're not getting a drink and then we can build upon that we have multiple

95
00:07:49,290 --> 00:07:50,590
parameters here.

96
00:07:50,640 --> 00:07:54,660
So if we're not old enough to buy a drink or we don't have enough money to buy a drink or we don't meet

97
00:07:54,780 --> 00:07:57,960
any of these scenarios different things can happen.

98
00:07:57,960 --> 00:08:04,470
Well you need to be thinking about as a developer program or even writing these scripts is all the scenarios

99
00:08:04,470 --> 00:08:08,190
that could happen in these situations you've got to think of the logic behind it.

100
00:08:08,490 --> 00:08:12,090
So when you're building out a script you're building out your first program.

101
00:08:12,090 --> 00:08:18,510
You need to think logically if I make an if statement or a conditional statement what's the logic behind

102
00:08:18,510 --> 00:08:19,070
it.

103
00:08:19,080 --> 00:08:25,110
So a lot of times for example in this scenario we might have thought OK well if I don't have that The

104
00:08:25,110 --> 00:08:29,910
Age or the money OK but you've got to think about what if I do have the age but not the money or I do

105
00:08:29,910 --> 00:08:31,950
have the money but not the age.

106
00:08:31,950 --> 00:08:35,580
So you have to think through everything in your head and make sure that it's all thinking and this just

107
00:08:35,580 --> 00:08:36,870
takes repetition.

108
00:08:36,870 --> 00:08:41,460
And just sitting down the best way is sitting down at the pen and paper and not writing this in code

109
00:08:41,460 --> 00:08:45,180
form but this writing this in a sense that makes sense to you.

110
00:08:45,180 --> 00:08:47,850
Thinking through it logically and then writing it out in code.

111
00:08:48,300 --> 00:08:52,530
So from here we're going to go ahead and move on to list in the next video.

112
00:08:52,530 --> 00:08:55,530
So once you are caught up here let's go ahead and move right over there.
